<template>
  <div class="singer-content">
    <div class="filter-wrap">
      <div class="seciton-wrap">
        <span class="section-type">热门类型:</span>
        <ul class="tabs-wrap">
          <li class="tab">
            <span
              class="title"
              :class="{ active: type == '-1' }"
              @click="type = '-1'"
              >全部</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: type == '1' }"
              @click="type = '1'"
              >男歌手</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: type == '2' }"
              @click="type = '2'"
              >女歌手</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: type == '3' }"
              @click="type = '3'"
              >乐队</span
            >
          </li>
        </ul>
      </div>
      <div class="order-wrap">
        <span class="order-type">歌手地区:</span>
        <ul class="tabs-wrap">
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '-1' }"
              @click="area = '-1'"
              >全部</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '7' }"
              @click="area = '7'"
              >华语</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '96' }"
              @click="area = '96'"
              >欧美</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '8' }"
              @click="area = '8'"
              >日本</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '16' }"
              @click="area = '16'"
              >韩国</span
            >
          </li>
          <li class="tab">
            <span
              class="title"
              :class="{ active: area == '0' }"
              @click="area = '0'"
              >其他</span
            >
          </li>
        </ul>
      </div>
    </div>
    <!-- 容器 -->
    <!-- 推荐 -->
    <div class="singer">
      <div class="items">
        <div
          v-for="item in singerList"
          :key="item.id"
          class="item"
          @click="tosearch(item.name)"
        >
          <div class="img-wrap">
            <img :src="item.picUrl" alt="" />
          </div>
          <div class="info-wrap">
            <div class="name">{{ item.name }}</div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        small
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="limit"
      >
      </el-pagination>
    </div>
    <br>
    <hr>
    <br>
  </div>
</template>

<script>
import { singerAll } from '@/api/singer'
export default {
  name: 'singerIndex',
  components: {},
  props: {},
  data () {
    return {
      area: '-1',
      type: '-1',
      // 每页数据
      limit: 40,
      // 页码
      page: 1,
      // 总条数
      total: 1000,
      // 歌手列表数据
      singerList: []
    }
  },
  computed: {},
  watch: {
    area () {
      this.page = 1
      this.getData()
    },
    type () {
      this.page = 1
      this.getData()
    }
  },
  created () {
    this.getData()
  },
  mounted () {},
  methods: {
    // 页码改变
    handleCurrentChange (val) {
      this.page = val
      this.getData()
    },
    async getData () {
      const { limit, area, type, page } = this
      const res = await singerAll(
        limit,
        area,
        type,
        (page - 1) * limit
      )
      this.singerList = res.data.artists
    },
    tosearch (keywords) {
      this.$router.push({
        name: 'm.search',
        params: {
          keywords
        }
      })
    }
  }
}
</script>

<style scoped lang="less">
.singer-content {
  padding-top: 20px;
  .filter-wrap {
    padding-left: 16px;
    text-align: center;
    > div {
      margin-bottom: 30px;
      vertical-align: baseline;
      display: flex;
      align-items: center;
      span {
        font-size: 12px;
        height: 100%;
        &.title {
          color: gray;
          cursor: pointer;
          padding: 6px 12px;
          &.active {
            color: #dd6d60;
            background-color: #fcf6f5;
            border-radius: 20px;
          }
          &::before {
            content: '';
          }
        }
      }
      ul {
        display: flex;
        li:not(:last-child) {
          border-right: 1px solid #f2f2f1;
        }
      }
    }
  }
  .singer {
    .items {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      .item {
        width: 65px;
        cursor: pointer;
        margin-left: 24px;
        margin-bottom: 30px;
        .img-wrap {
          width: 100%;
          position: relative;
          img {
            width: 100%;
            border-radius: 30px;
          }
        }
        .info-wrap {
          .name {
            font-size: 12px;
            overflow: hidden;
            text-overflow:ellipsis;
            white-space:nowrap;
            text-align: center;
          }
        }
      }
    }
  }
}
</style>
